package com.wms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wms.bean.PageBean;
import com.wms.dto.TaskDetailDTO;
import com.wms.entity.StockTakingTaskDetailList;
import com.wms.mapper.StockTakingTaskDetailListMapper;
import com.wms.service.StockTakingTaskDetailListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockTakingTaskDetailListServiceImpl implements StockTakingTaskDetailListService {
    
    @Autowired
    private StockTakingTaskDetailListMapper stockTakingTaskDetailListMapper;

    /**
     * 查询盘点任务明细(列表)
     * @param code
     * @return
     */
    @Override
    public StockTakingTaskDetailList queryTaskDetailByList(String code) {
        // 1. 查询任务基本信息
        StockTakingTaskDetailList taskDetail = stockTakingTaskDetailListMapper.queryTaskDetailByList(code);
        if (taskDetail == null) {
            return null;
        }

        // 2. 查询该任务下的所有商品明细
        List<TaskDetailDTO> itemList = stockTakingTaskDetailListMapper.queryTaskDetailByListDTO(taskDetail.getTaskId());
        
        // 3. 设置商品列表到任务详情中
        taskDetail.setItemList(itemList);

        return taskDetail;
    }

    /**
     * 统计该任务下的商品总数
     * @param code
     * @return
     */
    @Override
    public int countTaskDetail(String code) {
        return stockTakingTaskDetailListMapper.countTaskDetail(code);
    }
}
